home *** CD-ROM | disk | FTP | other *** search
/ DOpus Plus / DOpus Plus.iso / Tutorial / C Guide / Simple_Module2 / DOS / DOS.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-27  |  5.0 KB  |  138 lines

  1. /*******************************************************************
  2.  
  3.    DOS.c
  4.     
  5.     Shows the usage of LaunchCLI() and LaunchWB(), ...
  6.     
  7.     
  8.     Time to be again a little bit lazy :-), because it is all simple
  9.     stuff...
  10.     
  11.     For testing -> remember the command is hidden. 
  12.  
  13. *********************************************************************/
  14. #define PARENT
  15. #include "/includes/Project.h"
  16.  
  17. #define HIDDEN_TEMPLATE "WB/K,CLI/K,NAME/K,VERSION/K"
  18. // With 
  19.  
  20. // - WB we do start a program in Workbench mode
  21.  
  22. // - CLI start a program in CLI mode
  23.  
  24. // - NAME does set an ENV variable "TEST" with the devicename/path of a file
  25. // - (ie. you enter "_hiddencommand_ NAME=WorkBench/disk.info" 
  26. //    ENV:TEST will be "HD0:disk.info" )
  27. //    Note: Sorry, for now you must use DOpus or whatever manually to see
  28. //          the result of this action.
  29. //          Later we could solve it ... :-)
  30.     
  31. // - VERSION tries to get this information and shows it within a requester
  32.  
  33. // Each command needs of course supplied a file/program
  34. // Argument passing to the programs to launch we do not here..., it would
  35. // only require to append them to the program name, but I am sure you know
  36. // how... :-)
  37.  
  38. void HiddenCommand( STRPTR args, IPCData *ipc, IPCData *main_ipc )
  39. {
  40.       // normally this count of variables should be enough to allocate
  41.       // the memory, but forgive me here ... :-)
  42.       // I want not make the includes to much heavy for the beginners
  43.        
  44.       FuncArgs *fargs;
  45.       char buffer[256], day[16], date[16], time[16];
  46.       BPTR lock;
  47.       short version, revision;
  48.       struct DateTime  dt;
  49.       
  50.       if( (fargs = ParseArgs(HIDDEN_TEMPLATE, args)) )
  51.         {
  52.              if( fargs->FA_Arguments[0] ) // Launch WB
  53.                {
  54.                     LaunchWBNew( (STRPTR) fargs->FA_Arguments[0], // program or even a guide, ...
  55.                                  NULL,                   // use default screen
  56.                                      FALSE,                  // do return immediate
  57.                                      4096,                   // default stack (does not override an icon)
  58.                                      "MultiView" );          // default tool  ( "    "    "      "   "  )
  59.                                      
  60.                    // done :-)
  61.                 }
  62.                 
  63.              if( fargs->FA_Arguments[1] ) // Launch CLI
  64.                {
  65.                     LaunchCLI( (STRPTR) fargs->FA_Arguments[1],   // program to launch
  66.                                NULL,                     // use default screen
  67.                                   NULL,                     // we have no lock...
  68.                                   NULL, NULL,               // we have also no input/output channels
  69.                                   LAUNCHF_WAIT,             // here our program should wait for the program ends
  70.                                                             // It does of course only work, if the program does not
  71.                                                                      // detach itself !  
  72.                                   NULL );                   // we didn't supply the LAUNCHF_STACK flag 
  73.                                                             // (else you should specify here the stack to use)
  74.                 }
  75.                 
  76.              if( fargs->FA_Arguments[2] ) // "Show" device/path
  77.                {
  78.                     // we does set a default, if Lock() does fail
  79.                     
  80.                     strcpy( buffer, "Lock() has failed" );
  81.                     
  82.                     if( (lock = Lock( (STRPTR) fargs->FA_Arguments[2], SHARED_LOCK)) )
  83.                       {
  84.                           DevNameFromLock( lock,    // lock to file/directory
  85.                                            buffer,  // string buffer to store the result
  86.                                                  256 );   // size of string buffer
  87.                                                  
  88.                           UnLock( lock );
  89.                       }                             
  90.                     
  91.                     // So let's do the next DOpus-DOS routine
  92.                     // KEEP THIS IN MIND - it is very useful to search failures
  93.                           
  94.                     SetEnv( "TEST",   // name of the ENV variable
  95.                             buffer,   // string buffer containing the value
  96.                             FALSE );  // set this to TRUE, if the variable should
  97.                                       // be created/overwritten in ENVARC: too
  98.                 }
  99.                 
  100.              if( fargs->FA_Arguments[3] ) // Get version/info
  101.             {
  102.                     GetFileVersion( (STRPTR) fargs->FA_Arguments[3], // filename 
  103.                                     &version,               // pointer to receive the version number
  104.                                          &revision,              // same for revision
  105.                                          &dt.dat_Stamp,          // DateStamp to get the creation date (if possible)
  106.                                          NULL );                 // we does not supply a progress handle (now...)
  107.                             
  108.                     // NOTE: I do not check here, if the time was valid.
  109.                     //       You may do a little bit finetuning here... :-)
  110.                     
  111.                     dt.dat_Format  = FORMAT_DOS;
  112.                     dt.dat_Flags   = 0;
  113.                     dt.dat_StrDay  = day;
  114.                     dt.dat_StrDate = date;
  115.                     dt.dat_StrTime = time;
  116.                           
  117.                     DateToStr( &dt );
  118.                                           
  119.                     sprintf( buffer, "Filename: %s\nVersion: %ld\nRevision: %ld\nCreation: %s on %s the %s",
  120.                              fargs->FA_Arguments[3],
  121.                                 version, revision,
  122.                                 time, day, date );
  123.                                 
  124.                     AsyncRequestTags( ipc,                // our ipc 
  125.                                       REQTYPE_SIMPLE,     // a simple requester
  126.                                             NULL,               // just open on default screen
  127.                                             NULL,               // no refresh callback
  128.                                             NULL,               // like before
  129.                                             AR_Message, buffer, // our "output"
  130.                                             AR_Button, DOpusGetString(locale, MSG_OKAY),
  131.                                             TAG_DONE );
  132.                 }
  133.                 
  134.              DisposeArgs( fargs );
  135.           }
  136. }
  137.  
  138.